let menus = [
  {
    id: 1,
    pid: 0,
    path: '/system',
    component: 'Layout',
    redirect: '/system/user',
    title: '系统管理',
    icon: 'el-icon-s-operation',
  },
  {
    id: 2,
    pid: 1,
    path: '/system/page',
    component: 'system/page',
    title: '页面设置',
  },
  {
    id: 3,
    pid: 1,
    path: '/system/user',
    component: 'system/user',
    title: '用户管理',
  },
  {
    id: 4,
    pid: 1,
    path: '/system/menu',
    component: 'system/menu',
    title: '菜单管理',
  },
  {
    id: 5,
    pid: 1,
    path: '/system/role',
    component: 'system/role',
    title: '角色管理',
  },
  {
    id: 11,
    pid: 0,
    redirect: "/data/dictionaries",
    path: '/data',
    component: 'Layout',
    title: '商城管理',
    icon: 'el-icon-collection',
  },
  {
    id: 12,
    hide:true,
    pid: 11,
    path: "/data/dictionaries",
    component: 'data/dictionaries',
    title: '字典管理',
  },
  {
    id: 13,
    pid: 11,
    path: "/data/classify",
    component: 'data/classify',
    title: '分类管理',
  }

]

module.exports = [
  {
    url: '/vue-admin-template/menus/list\.*',
    type: 'get',
    response: config => {
      const { page = 1, limit = 10 } = config.query;
      const list = [...menus].reverse();
      const index = (page - 1) * limit;
      const howmany = limit
      const data = list.splice(index, howmany)
      return {
        code: 200,
        data: {
          list: data,
          total: menus.length
        }
      }
    }
  },


  {
    url: '/vue-admin-template/menus/create',
    type: 'post',
    response: config => {
      let { id, pid = 0 } = config.body
      config.body.id = Number(id)
      if (config.body.target == "false") {
        config.body.target = false;
      } else {
        config.body.target = true;
      }
      if (config.body.hidden == "false") {
        config.body.hidden = false;
      } else {
        config.body.hidden = true;
      }
      config.body.pid = pid
      if (id) {
        id = Number(id)
        const rolesList = [...menus]
        let index = rolesList.map(val => val.id).indexOf(id)
        menus[index] = config.body
      } else {
        config.body.id = + new Date()
        config.body.c_time = new Date().format('yyyy-MM-dd hh:mm:ss')
        menus.push(config.body)
      }
      return {
        code: 20000,
        data: !id ? '添加成功' : "修改成功"
      }
    }
  },
  // user router
  {
    url: '/router/get',
    type: 'get',
    response: () => {
      return {
        code: 20000,
        data: menus
      }
    }
  },
  // user router
  {
    url: '/vue-admin-template/menus/deleteMenu',
    type: 'post',
    response: config => {

      let { id } = config.body;
      const list = [...menus];
      id = Number(id)
      const index = list.map(val => val.id).indexOf(id);
      if (index > -1) {
        menus.splice(index, 1)
        return {
          code: 200,
          data: '删除成功'
        }
      }

      else {
        return {
          code: 40000,
          data: '删除失败'
        }
      }
    }
  },



]
